package com.ctshk.sapp.system.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.UserMenuDTO;
import com.ctshk.rpc.system.req.UserOftenMenuReq;
import com.ctshk.rpc.system.service.IUserOftenMenuService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户常用菜单 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-26
 */
@RestController
@RequestMapping("/user-often-menu")
public class UserOftenMenuController extends BaseController {

    @DubboReference
    private IUserOftenMenuService userOftenMenuService;

    @ApiOperation(value = "用户菜单列表", notes = "用户菜单列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "用户菜单列表", operDesc = "用户菜单列表")
    @PostMapping(value = "/list")
    public Result<List<UserMenuDTO>> list() {
        TokenUser currentUser = getCurrentUser(getRequest());
        return Result.success(userOftenMenuService.list(currentUser));
    }

    @ApiOperation(value = "设置用户常用菜单", notes = "设置用户常用菜单")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "设置用户常用菜单", operDesc = "设置用户常用菜单")
    @PostMapping("/save")
    public Result saveUserOftenMenu(@RequestBody @Valid UserOftenMenuReq userOftenMenuReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        return userOftenMenuService.saveUserOftenMenu(userOftenMenuReq, userId);
    }

    @ApiOperation(value = "常用菜单列表", notes = "常用菜单列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "常用菜单列表", operDesc = "常用菜单列表")
    @PostMapping(value = "/often-menu-list")
    public Result<List<UserMenuDTO>> oftenMenuList() {
        TokenUser currentUser = getCurrentUser(getRequest());
        return Result.success(userOftenMenuService.oftenMenuList(currentUser));
    }

}
